<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>热门动弹</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <style>
	#more, .more{
		margin-top: 0px;
		padding-bottom: 15px;
		text-align: center;
	}
	.aui-text-default {
		word-break: break-all; word-wrap:break-word;
	}
	.aui-icon-appreciate, .aui-icon-appreciatefill{
		padding: 0 10px 0 10px;
	}
    </style>
</head>
<body>
    <div class="aui-content">
        <ul class="aui-user-view" id="list">
            <!--li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/523/1047279_50.jpg?t=1418696812000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">君遥</span>
                    <h5 class='aui-text-default'>最近猛的一下子手里抓到3个资源，不知道怎么选择了，一号女，长相一般普普通通或者说偏下，不过在北京有房，工作护士；二号女，韩国留学7年，硕士毕业，北京工作金融方面；三号女，年纪小，92年，长相偏上，护士工作。这个，我该怎么选择。。。</h5>
                    <p><img src="http://static.oschina.net/uploads/space/2015/1013/194556_ERoX_2479387_thumb.jpg" /></p>
                    <p><font class="aui-text-primary">哇的、啊盛大风、格是</font> 等45人觉得很赞</p>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-appreciate"></font>　<font class="aui-iconfont aui-icon-comment"></font> 234</p>
				    </a>
                </div>
            </li-->
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript" src="../script/OSChinaApi.js" ></script>
<script type="text/javascript">
	var page = 0;
	apiready = function(){
		// 下拉刷新
		api.setRefreshHeaderInfo({
	        visible: true,
	        loadingImg: 'widget://image/ptr_pull.png',
	        bgColor: '#efeff4',
	        textColor: '#959595',
	        textDown: '下拉可刷新',
	        textUp: '松开立即刷新',
	        showTime: true
		}, function(ret, err){
		    //从服务器加载数据，完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
		    getTweetList(0);
		});
		
		// 首次加载时设置下拉刷新组件为刷新中状态
		api.refreshHeaderLoading();
		
	};
	
	/*
	 * 获取动弹列表
	 * @param  integer pageIndex  	页码，第一页是从0开始的
	 */
	function getTweetList(pageIndex){

		var listhtml = '';
		var url = OpenAPI.tweet_list + '&uid=-1&pageIndex=0';
	    var more = $api.byId("more");
	    
		api.ajax({
		    url: url,
		    method: 'get',
		    timeout: 30,
		    dataType: 'text',
		    returnAll: false,
		},function(ret,err){
		    if (ret) {
				var trans = api.require('trans');
				trans.parse({
				    data:ret
				},function(ret,err){
				    if(ret) {
				    	var tweetCount = parseInt(ret.oschina.tweetCount); //总动弹数 
						var lastPage = tweetCount/20;
						
						
						var more = $api.byId("more");
						if(more){
							 $api.remove(more);
						}
				    	for(var i=0; i<ret.oschina.tweets.tweet.length; i++){

				    		var portrait = '../image/widget_dface.png';
				    		if(typeof(ret.oschina.tweets.tweet[i].portrait) == 'string' && ret.oschina.tweets.tweet[i].portrait.length > 0){
				    			portrait = ret.oschina.tweets.tweet[i].portrait;
				    		}
							listhtml += '<li class="aui-user-view-cell aui-img" tapmode onclick="openTweet('+ret.oschina.tweets.tweet[i].id+')">';
							listhtml += '<img class="aui-img-object aui-pull-left" src="'+ portrait +'" width="48px" height="48px" tapmode onclick="openUserInfo( '+ ret.oschina.tweets.tweet[i].authorid+' );event.cancelBubble=true;">';
							listhtml += '<div class="aui-img-body">';
							listhtml += '<span class="aui-text-primary">'+ ret.oschina.tweets.tweet[i].author +'</span>';
							listhtml += '<h5 class="aui-text-default">'+ htmlspecialchars(ret.oschina.tweets.tweet[i].body) +'</h5>';
							if(typeof(ret.oschina.tweets.tweet[i].imgSmall) == 'string' && ret.oschina.tweets.tweet[i].imgSmall.length > 0){
								listhtml += '<p><img src="'+ ret.oschina.tweets.tweet[i].imgSmall +'" tapmode onclick="imageBrowser(\''+ ret.oschina.tweets.tweet[i].imgBig +'\');event.cancelBubble=true;"/></p>';
							}
							listhtml += '<p id="likeList_'+ret.oschina.tweets.tweet[i].id+'">';
							if( typeof(ret.oschina.tweets.tweet[i].likeList.user) == 'object' ){
									var j=0, likeUserList='', some='';
									do
									{
										if(typeof(ret.oschina.tweets.tweet[i].likeList.user.name) == 'string'){
											likeUserList += ret.oschina.tweets.tweet[i].likeList.user.name + '、';
										}else{
											likeUserList += ret.oschina.tweets.tweet[i].likeList.user[j].name + '、';
										}
										
										if( j>2 ){
											some = '等';
											break;
										}
										j++;
									}
									while (j<ret.oschina.tweets.tweet[i].likeList.user.length);
									likeUserList = likeUserList.substring(0, likeUserList.length-1);
									listhtml += '<font class="aui-text-primary" id="userList_'+ret.oschina.tweets.tweet[i].id+'">' +likeUserList+ '</font> '+ some + '<font id="likeCount_'+ret.oschina.tweets.tweet[i].id+'">' + ret.oschina.tweets.tweet[i].likeCount +'</font>人觉得很赞';
							}
							listhtml += '</p>';
							listhtml += '<a class="aui-pull-left">';
							listhtml += '<p class="aui-ellipsis-1"><font class="aui-iconfont aui-icon-time"></font> '+ friendly_time(ret.oschina.tweets.tweet[i].pubDate) +'　<font class="aui-iconfont aui-icon-mobile"></font> ' + getAppClientName(ret.oschina.tweets.tweet[i].appclient) + '</p>';
							listhtml += '</a>';
							listhtml += '<a class="aui-pull-right">';
							var isLike = 'aui-icon-appreciate';
							if( parseInt(ret.oschina.tweets.tweet[i].isLike) == 1){
								isLike = 'aui-icon-appreciatefill aui-text-primary';
							}
							listhtml += '<p class="aui-ellipsis-1"><font id="isLike_'+ret.oschina.tweets.tweet[i].id+'" class="aui-iconfont '+ isLike +'"  isLike="'+ret.oschina.tweets.tweet[i].isLike+'" tapmode onclick="tweetListMakeAsLove( '+ret.oschina.tweets.tweet[i].id+', '+ret.oschina.tweets.tweet[i].authorid+' );event.cancelBubble=true;"></font>　<font class="aui-iconfont aui-icon-comment"></font> ' + ret.oschina.tweets.tweet[i].commentCount + '</p>';
							listhtml += '</a>';
							listhtml += '</div>';
							listhtml += '</li>';
				    	}
				    	
				        if(pageIndex == 0){
				        	$api.html($api.byId('list'), listhtml);
				        }else{
				        	$api.append($api.byId('list'), listhtml);
				        }
				        page += 1;
				        if(page < lastPage){
				        	$api.after($api.byId('list'), '<p id="more" tapmode onclick="getTweetList('+page+')">点击加载更多</p>');
				        }else{
				        	$api.after($api.byId('list'), '<p id="more">全部加载完毕</p>');
				        }
				        
				    }else{
					    if(more){
					        $api.text(more, '加载失败，点击重试');
					    }
				        log(err.msg);
				    }
				});
		    }else {
			    if(more){
			        $api.text(more, '加载失败，点击重试');
			    }
		        log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
		    	showAjaxErrMsg(err.code);
		    }
		    api.refreshHeaderLoadDone();
		    setTimeout("api.parseTapmode()", 100);	// 等0.1秒在执行
		});
	}
</script>
</html>